package com.miage.itrading.gui;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.beans.PropertyVetoException;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import com.miage.itrading.entites.Cotation;
import com.miage.itrading.gui.GraphDurees.Duree;

public class FenetrePrincipale  extends JFrame implements ActionListener {
    JDesktopPane desktop;
	
	public PartieCentrale	centre;
	public HautDePage		enTete;
	public PartieGauche		gauche;
	public PartieDroite		droite;
	public RSSWidget 		rss;
	


	private static final long serialVersionUID = 8735828663622946890L;
	
	public FenetrePrincipale() {
		
		super("iTrading");
		
        desktop = new JDesktopPane();

        enTete = new HautDePage(this);
        gauche = new PartieGauche(this);
        droite = new PartieDroite(this);
        centre = new PartieCentrale(this);
        rss	   = new RSSWidget(this);
        
        desktop.add(enTete);
        desktop.add(gauche);
        desktop.add(rss);
        desktop.add(droite);
        desktop.add(centre);
        
        enTete.setVisible(true);
        rss.setVisible(true);
        gauche.setVisible(true);
        droite.setVisible(true);
        centre.setVisible(true);
        
       
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
        setSize(getScreenSize().width, getScreenSize().height);
		desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
        
        setContentPane(desktop);
        setJMenuBar(new Menu());
        
        setVisible(true);
    }
	
	public Dimension getScreenSize() {
		return Toolkit.getDefaultToolkit().getScreenSize();
	}
	
	public void afficheCours(Cotation c) {
		gauche.setCotation(c);
		centre.setDonnees(c, Duree.HISTORIQUE);
			
		centre.build();
		gauche.build();
	}
	
	public Cotation getCotationAffichee() {
		return gauche.getCotation();
	}

	public void actionPerformed(ActionEvent e) {
        if ("quit".equals(e.getActionCommand())) {
        	System.exit(0);
        }
	}	
}
